<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Port Scan</title>
    <script type="application/javascript">
        var AttackAPI = {
            PortScanner: {}
        };
        AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) {
            var timeout = (timeout == null) ? 100 : timeout;
            var img = new Image();
            img.onerror = function () {
                if (!img) {
                    return;
                }
                img = undefined;
                callback(target, port, 'open');
            };
            img.onload = img.onerror;
            img.src = 'http://' + target + ':' + port;
            setTimeout(function () {
                if (!img) {
                    return;
                }
                img = undefined;
                callback(target, port, 'closed');
            }, timeout);
        };

        AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout) {
            for (index = 0; index < ports.length; index++) {
                AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);
            }
        };

        var callback = function (target, port, status) {
            var result = document.getElementById('result');
            result.value += target + ':' + port + ' ' + status + "\n";
        };
        var scan = function (form) {
            var result = document.getElementById('result');
            result.value = "";
            AttackAPI.PortScanner.scanTarget(callback, form.target.value, form.port.value.split(','), form.timeout.value);
        };
    </script>
</head>
<body>
<div>
    <form>
        <label for="target">target</label>
        <input type="text" name="target" id="target" value=""/><br/>
        <label for="port">port</label>
        <input type="text" name="port" id="port" value="80"/><br/>
        <label for="timeout">timeout</label>
        <input type="text" name="timeout" id="timeout" value="1000"/><br/>
        <label for="result">result</label>
        <textarea name="result" id="result" cols="50" rows="10"></textarea><br/>
        <input type="button" value="scan" onclick="scan(this.form)"/>
    </form>
</div>
</body>
</html>